
function MyStack(){
	this.dataStack = [];
	this.minStack = [];
}

MyStack.prototype.push = function(newValue){
	if( this.minStack.length===0 || newValue<=this.getMin() ){
		this.minStack.push(newValue);
	}
	this.dataStack.push(newValue);
	console.log(' push : '+ newValue );
	this.show();
}

MyStack.prototype.pop = function(){
	var value;
	if( this.dataStack.length === 0 ){
		throw new Error('Your stack is empty ');
	}
	value = this.dataStack.pop();
	if( value == this.getMin() ){
		this.minStack.pop();
	}

	console.log(' pop: '+ value);
	this.show();
	return value;
}

MyStack.prototype.getMin = function(){
	if( this.minStack.length === 0 ) {
		throw new Error('Your stack is empty ');
	}
	return this.minStack[this.minStack.length-1];
}

MyStack.prototype.show = function(){
	console.log(' data : '+ this.dataStack.join(','));
	console.log(' min : '+ this.minStack.join(','));
	console.log(' min value: '+ this.getMin() );
	console.log('=================');
}

	
var idx;
var stack = new MyStack();
stack.push(23);
stack.push(25);
stack.push(2);
stack.push(67);
stack.push(1);
stack.push(1);

for( idx=0;idx<6;idx++ ){
	stack.pop();
}

